import React, { useEffect, useState } from 'react';
// Mock response data
const mockResponses = {
  dashboardStats: {
    activeProxies: 27,
    monthlyTraffic: '1.2 TB',
    availability: '99.8%',
    pendingTickets: 2,
    recentActivities: [{
      id: 1,
      text: '获取了5个新代理',
      time: '2小时前'
    }, {
      id: 2,
      text: 'API密钥已更新',
      time: '1天前'
    }, {
      id: 3,
      text: '工单 #12345 已解决',
      time: '3天前'
    }]
  },
  proxyList: [{
    id: 1,
    ip: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
    port: 8080,
    location: '美国, 纽约',
    status: 'active',
    expires: '2023-09-15'
  }, {
    id: 2,
    ip: '2001:0db8:85a3:0000:0000:8a2e:0370:7335',
    port: 8080,
    location: '德国, 柏林',
    status: 'active',
    expires: '2023-09-15'
  }, {
    id: 3,
    ip: '2001:0db8:85a3:0000:0000:8a2e:0370:7336',
    port: 8080,
    location: '日本, 东京',
    status: 'active',
    expires: '2023-09-15'
  }, {
    id: 4,
    ip: '2001:0db8:85a3:0000:0000:8a2e:0370:7337',
    port: 8080,
    location: '英国, 伦敦',
    status: 'active',
    expires: '2023-09-15'
  }, {
    id: 5,
    ip: '2001:0db8:85a3:0000:0000:8a2e:0370:7338',
    port: 8080,
    location: '法国, 巴黎',
    status: 'active',
    expires: '2023-09-15'
  }]
};
// Custom hook for fetching data with built-in mocking
export function useFetchData(endpoint, initialData = null) {
  const [data, setData] = useState(initialData);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);
  useEffect(() => {
    setLoading(true);
    // Simulate API request with mock data
    setTimeout(() => {
      if (endpoint === '/dashboard/stats') {
        setData(mockResponses.dashboardStats);
      } else if (endpoint === '/proxies') {
        setData(mockResponses.proxyList);
      } else {
        // Default mock response for other endpoints
        setData({
          success: true,
          message: 'Mock data for ' + endpoint
        });
      }
      setLoading(false);
    }, 500); // Simulate network delay
  }, [endpoint]);
  return {
    data,
    loading,
    error
  };
}
// Mock API functions
export const api = {
  getDashboardStats: () => Promise.resolve(mockResponses.dashboardStats),
  getProxies: () => Promise.resolve(mockResponses.proxyList),
  createProxy: data => Promise.resolve({
    success: true,
    proxy: {
      id: Date.now(),
      ...data
    }
  }),
  updateProxy: (id, data) => Promise.resolve({
    success: true,
    proxy: {
      id,
      ...data
    }
  }),
  deleteProxy: id => Promise.resolve({
    success: true,
    message: `Proxy ${id} deleted`
  })
  // Add more API methods as needed
};
export default api;